//acwing


//https://www.acwing.com/problem/content/909/



#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=1e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//

int n;
struct Range
{
    int l, r;
    bool operator< (const Range &W)const //重载小于号,用于sort是默认调用range这个类的<排序
    {
        return l < W.l;
    }
}range[N];

int main()
{
	close();
    int st, ed;//需要覆盖的区间开始st,ed结尾
    cin>>st>>ed;
    cin>>n;
    for (int i = 0; i < n; i ++ )
    {
        int l, r;
        cin>>l>>r;
        range[i] = {l, r};
    }

    sort(range, range + n);

    int res = 0;
    bool ok = false;
    for (int i = 0; i < n; i ++ )
    {
        int j = i, r = -2e9;
        while (j < n && range[j].l <= st)//不会走回头路,所以是O(n)的复杂度
        {
            r = max(r, range[j].r);
            j ++ ;
        }

        if (r < st)
        {
            res = -1;
            break;
        }

        res ++ ;
        if (r >= ed)
        {
            ok = true;
            break;
        }

        st = r;
        i = j - 1;//退出的时候还加了一次
    }

    if (!ok) res = -1;
    cout<<res;

    return 0;
}


//将所有端点按左端点从小到大排序

//从前往后依次枚举每个区间

//每次选取l能覆盖st左端点区间,r最靠右的区间

//然后更新st变成刚才选的r